using Microsoft.VisualBasic;
using Microsoft.VisualBasic.CompilerServices;
using SJVars;
using SJXmlP.XMLClasses;
using System;
using System.Collections;
using System.IO;
using yW5Lib;

namespace yWriter6
{
	[StandardModule]
	internal sealed class modSaveSynopsis
	{
		public static void SaveSynopsis(clsProject cProject)
		{
			string str = "Auto_Synopsis.txt";
			str = cProject.ProjectPath() + str;
			if (cProject.ChapterCount != 0)
			{
				clsCollection<int> clsCollection = new clsCollection<int>();
				frmPickChapters frmPickChapters = new frmPickChapters(ref cProject);
				frmPickChapters.ShowDialog();
				if (!frmPickChapters.Cancelled)
				{
					clsCollection = frmPickChapters.PickedIDs;
					StreamWriter streamWriter = clsShared.cFile.OpenOutputStream(str);
					streamWriter.WriteLine(cProject.Title + " synopsis");
					streamWriter.WriteLine("");
					IEnumerator enumerator = default(IEnumerator);
					try
					{
						enumerator = clsCollection.GetEnumerator();
						int value = default(int);
						while (enumerator.MoveNext())
						{
							int iD = Conversions.ToInteger(enumerator.Current);
							clsChapter clsChapter = cProject.get_ChapterByID(iD);
							streamWriter.WriteLine("");
							streamWriter.WriteLine(clsChapter.Title);
							streamWriter.WriteLine("");
							int sceneCount = clsChapter.SceneCount;
							for (int i = 1; i <= sceneCount; i++)
							{
								clsScene clsScene = cProject.get_SceneByID(clsChapter.get_SceneIDByIndex(i));
								if (frmPickChapters.WithUnused | !clsScene.Unused)
								{
									streamWriter.WriteLine("  " + Conversions.ToString(value) + "." + Conversions.ToString(i) + " " + clsScene.DescText);
									if (i < clsChapter.SceneCount)
									{
										clsScene clsScene2 = cProject.get_SceneByID(clsChapter.get_SceneIDByIndex(i + 1));
										if (frmPickChapters.WithUnused | !clsScene2.Unused)
										{
											streamWriter.WriteLine("");
											streamWriter.WriteLine(Strings.Space(40) + "* * *");
											streamWriter.WriteLine("");
										}
									}
								}
							}
						}
					}
					finally
					{
						if (enumerator is IDisposable)
						{
							(enumerator as IDisposable).Dispose();
						}
					}
					streamWriter.Close();
					clsShared.cLang.TransMsgBox("Synopsis saved to @1@", MsgBoxStyle.OkOnly, "", str);
				}
			}
		}
	}
}
